import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - 并发管理/请求定义（并发程序）
 * @date: 2018-9-10
 * @version: 1.0.0


 */
import request from 'utils/request';
import { CPAAS_SDR } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 请求API前缀
 * @type {string}
 */

var prefix = "".concat(CPAAS_SDR, "/v1");
/**
 * 数据查询
 * @async
 * @function fetchConcurrentList
 * @param {object} params - 查询条件
 * @returns {object} fetch Promise
 */

export function fetchConcurrentList(_x) {
  return _fetchConcurrentList.apply(this, arguments);
}
/**
 * 创建
 * @async
 * @function createConcurrent
 * @param {String} params - 保存参数
 */

function _fetchConcurrentList() {
  _fetchConcurrentList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/concurrents") : "".concat(prefix, "/concurrents"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchConcurrentList.apply(this, arguments);
}

export function createConcurrent(_x2) {
  return _createConcurrent.apply(this, arguments);
}
/**
 * 修改
 * @async
 * @function updateConcurrent
 * @param {String} params.enabledFlag - 是否启用
 */

function _createConcurrent() {
  _createConcurrent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/concurrents") : "".concat(prefix, "/concurrents"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _createConcurrent.apply(this, arguments);
}

export function updateConcurrent(_x3) {
  return _updateConcurrent.apply(this, arguments);
}
/**
 * 查询详情
 * @async
 * @function fetchConcurrentDetail
 * @param {Object} params - 查询参数
 */

function _updateConcurrent() {
  _updateConcurrent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/concurrents") : "".concat(prefix, "/concurrents"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateConcurrent.apply(this, arguments);
}

export function fetchConcurrentDetail(_x4) {
  return _fetchConcurrentDetail.apply(this, arguments);
}
/**
 * 删除并发程序参数（行）
 * @async
 * @function deleteLine
 * @param {object} params - 请求参数
 * @param {!string} params.concParamId - 参数ID
 */

function _fetchConcurrentDetail() {
  _fetchConcurrentDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/concurrents/").concat(params.concurrentId) : "".concat(CPAAS_SDR, "/v1/concurrents/").concat(params.concurrentId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _fetchConcurrentDetail.apply(this, arguments);
}

export function deleteLine(_x5) {
  return _deleteLine.apply(this, arguments);
}
/**
 * 获取已分配的权限
 * @async
 * @function fetchTemplateDetail
 * @param {object} params - 查询条件
 * @returns {object} fetch Promise
 */

function _deleteLine() {
  _deleteLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/concurrent-params") : "".concat(prefix, "/concurrent-params"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteLine.apply(this, arguments);
}

export function fetchAssignedPermission(_x6) {
  return _fetchAssignedPermission.apply(this, arguments);
}
/**
 * 分配权限
 * @async
 * @function createPermission
 * @param {String} params - 保存参数
 */

function _fetchAssignedPermission() {
  _fetchAssignedPermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/conc-permissions/").concat(params.concurrentId) : "".concat(prefix, "/conc-permissions/").concat(params.concurrentId), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _fetchAssignedPermission.apply(this, arguments);
}

export function createPermission(_x7) {
  return _createPermission.apply(this, arguments);
}
/**
 * 修改权限
 * @async
 * @function updatePermission
 * @param {String} params
 */

function _createPermission() {
  _createPermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/conc-permissions") : "".concat(prefix, "/conc-permissions"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _createPermission.apply(this, arguments);
}

export function updatePermission(_x8) {
  return _updatePermission.apply(this, arguments);
}

function _updatePermission() {
  _updatePermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/conc-permissions") : "".concat(prefix, "/conc-permissions"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _updatePermission.apply(this, arguments);
}